// pages/order/list/index.js
import {reqOrderList} from '@/api/orderpay'
Page({
  // 页面的初始数据
  data: {
    orderList: [1, 2, 3],
    params:{
      page:1,
      limit:5
    },
    total:0,
    isLoading:false
  },

  //上拉加载更多
  async onReachBottom(){
    // const {page,limit} = this.data.params
    if(!this.data.isLoading){
      this.data.params.page+=1
      this.data.isLoading = true
    const res =  await reqOrderList(this.data.params.page,5)
    this.data.isLoading = false
    // console.log(res,'res');
    //如果新增为0，说明没有更多
    if (this.data.orderList.length === this.data.total){
      wx.toast({title:"没有更多"})
      return
    } 
    //合并订单
    this.setData({
      orderList:[...this.data.orderList,...res.data.records]
    })
    
    }
    

  },
  
  async getOrderList(){
    const {page,limit} = this.data.params
    const res = await reqOrderList(page,limit)//{page:页码,limit:每页条数}
    console.log(res);
    if (res.code === 200) {
      this.setData({
        orderList:res.data.records,
        total: res.data.total
      })
    }
  },

  onShow(){
    this.getOrderList()
    
  }
  
})
